import cv2
import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0, 10)
y = np.random.normal(5, 4, (10,)).astype(np.int32)
plt.plot(x, y, 'ro')

# 获取所有的坐标点
x = x.reshape(10, 1)
y = y.reshape(10, 1)
points = np.concatenate((x, y), axis=1)

# 凸包检测 convexHull
result = cv2.convexHull(points)
print(len(result))

# 将上述检测到的凸包点，两两绘制连线
for i in range(len(result)):
    x1, y1 = result[i][0]
    x2, y2 = result[(i + 1) % len(result)][0]
    plt.plot([x1, x2], [y1, y2], 'b--')

plt.show()
